package com.sjc.grpc.server.service;

import com.sjc.demo.java.grpc.rpc.HelloRequest;
import com.sjc.demo.java.grpc.rpc.HelloResponse;
import com.sjc.demo.java.grpc.rpc.HelloServiceGrpc;
import io.grpc.stub.StreamObserver;
import org.springframework.stereotype.Service;

@Service
public class RpcHelloServiceImpl extends HelloServiceGrpc.HelloServiceImplBase {
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
        HelloResponse response = HelloResponse.newBuilder().setMessage("hello, " + request.getUserName()).build();
        // 响应RPC客户端的RPC调用请求
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}
